package cn.fl.repay.service.impl;

import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.fl.repay.constant.RepayConstant;
import cn.fl.repay.service.IInsOfflineRepayDtlService;
import cn.fl.repay.service.OfflineRepayStrategy;
import cn.fl.repay.vo.InsOfflineRepayDtlVO;
import cn.fl.repay.vo.InsOfflineRepayLogVO;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author: leon (lipengd@shiqiao.com)
 * @createDate: 2020/7/2
 * @company: (C) Copyright shiqiao 2020
 * @since: JDK 1.8
 * @description: 信托和我司策略类，未来如果每家信托规则都不同，则继续拆分为具体的信托机构策略类
 */
@Service
public class TrustOfflineRepayStrategy implements OfflineRepayStrategy {

    @Autowired
    private IInsOfflineRepayDtlService insOfflineRepayDtlService;

    @Override
    public boolean support(String repayType) {
        if (StringUtils.isEmpty(repayType) || repayType.equals(RepayConstant.REPAY_TYP_CD_PD)) {
            return false;
        }
        return true;
    }

    @Override
    public List<InsOfflineRepayDtlVO> getRepayDtl(String crCntNo, String repayType, String actPayDt) {
        if ( !support(repayType) ){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "该功能不支持信托按期还款.");
        }

        return insOfflineRepayDtlService.getTrustSettleRepayDtl(crCntNo, actPayDt);
    }

    @Override
    public void checkRepayData(InsOfflineRepayLogVO repayLogVO, List<InsOfflineRepayDtlVO> repayDtlList) {
        BaseLogUtils.newLogger("信托和我司线下还款暂不校验还款申请数据, RepayLogVO: {}, RepayDtlVOList: {}"
                , JSON.toJSONString(repayLogVO), JSON.toJSONString(repayDtlList)).debug();
    }
}
